﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ornament.Messages.Contents
{
    public delegate void FillContentValuesMapHandler<T>(T contentValue, Dictionary<string, string> valueMaps);

    public class GenericContent<T> : Content
    {
        private static readonly Dictionary<Type, Dictionary<string, string>> typeMappings = new Dictionary<Type, Dictionary<string, string>>();

        FillContentValuesMapHandler<T> mapsHandler;

        public GenericContent()
        {
            mapsHandler = new FillContentValuesMapHandler<T>(FillContentToValueMaps);
        }

        public GenericContent(FillContentValuesMapHandler<T> contentValueMapping)
        {
            if (contentValueMapping == null)
            {
                throw new ArgumentNullException("contentValueMapping");
            }
            mapsHandler = contentValueMapping;

        }
        /// <summary>
        /// 
        /// </summary>
        public new virtual T Value
        {
            get { return (T)base.Value; }
            set { base.Value = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <param name="valueMaps"></param>
        protected override void FillContentValue(Info info, Dictionary<string, string> valueMaps)
        {
            mapsHandler(this.Value, valueMaps);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="beFillValue"></param>
        /// <param name="valueMaps"></param>
        protected virtual void FillContentToValueMaps(T beFillValue, Dictionary<string, string> valueMaps)
        {
        }
    }
}
